package AES;

class BitDemo {

    public static void main(String[] args) {
        String temp = "";
        String string = "abcdefghijklmnopqrstuvwxyz";
        byte[] stringBytes = string.getBytes();
        boolean[][] bytes = convertByteToBits(stringBytes);
        System.out.println("number of bytes: " + bytes.length);
        System.out.println("number of bits:  " + bytes.length*8);

        for (int j = 0; j < bytes.length; j++) {
            for (int i = 7; i >= 0; i--) {
                if (bytes[j][i]) {
                    temp = temp.concat("1");
                } else {
                    temp = temp.concat("0");
                }
            }
            System.out.print(temp);
            temp = "";
            
        }
    }

    public static boolean[][] convertByteToBits(byte[] b) {
        boolean[][] bytes = new boolean[b.length][];
        boolean[] bits = null;

        for (int j = 0; j < b.length; j++) {
            bits = new boolean[8];
            for (int i = 0; i < bits.length; i++) {
                bits[i] = ((b[j] & (1 << i)) != 0);
            }
            bytes[j] = bits;
        }
        return bytes;
    }
}
